<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head>
	<style type="text/css">
	   *{
	      margin: 0px;
	      padding: 0px;
	      font-size: 12px;
	   }
	</style>
</head>
<body class="gray-bg">
<div class="creditbody">
    <div class="iboxtitle">
        <span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;业务受理>变更主借人</span>
    </div>
    <div class="ibox-content ibox-zxsearchqu ">
         <div class="row">
             <div class="col-xs-12 col-sm-12 col-md-12 col-lg-5">
            	 <div class="row">
	               <!--  <div class="col-xs-12 col-sm-12 col-md-12 col-lg-3">    
	                  <label class="sr-only">数据来源：</label>
	                  <select id="datasources" name="datasources" class="select-control" onchange="query();">
	                  		<option value="1" selected="selected">手工模式</option>
	                  		<option value="0">接口模式</option>
	                  </select>
	                 </div> -->
            	 	<div class="col-xs-12 col-sm-12 col-md-12 col-lg-4">  
	              	   <label class="sr-only">主借人：</label>
	                  <input type="text" placeholder="主借人名称" id="zhujierenName" name="zhujierenName" class="form-control">
	                </div>
            	 	<div class="col-xs-12 col-sm-12 col-md-12 col-lg-4">  
	              	   <label class="sr-only">配偶名称：</label>
	                  <input type="text" placeholder="配偶名称" id="peiouName" name="peiouName" class="form-control">
	                </div>
	                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-4">    
	                  <label class="sr-only">配偶身份证号：</label>
	                  <input type="text" placeholder="配偶身份证" id="peiouNo" name="peiouNo" class="form-control">
	                 </div> 
	               </div>  
             </div>
             <div class="col-xs-12 col-sm-12 col-md-12 col-lg-3">
             		<div class="row">
             			<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">  
             				<input id="startDateStart" name="startDateStart" placeholder="开始时间" class="laydate-icon form-control">
             			</div>
             			<label class="hxleft">至</label>
                   <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">  
                   	<input id="startDateEnd" name="startDateEnd" placeholder="结束时间" class="laydate-icon form-control">
                   </div>
                  </div>
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-4" id="buttonall">
	                <button class="btn dpbtn_blue_null" type="button" onclick="query(0,0);">当日</button>
					<button class="btn dpbtn_blue_null" type="button" onclick="query(-1,-1);">昨日</button>
					<button class="btn dpbtn_blue_null butactive" type="button" onclick="query(-6,0);">近7日</button>
	             	<button class="zhixcx" type="button" onclick="query();">执行查询</button>
              </div>
    	</div>
    </div>
   <div class="ibox-content">
   		<span class="warning-label"><span class="red-dp-circle"></span>30天内查询过配偶征信信息（征信状态为正常或者关注），且业务状态为初审单初审中（包括）之前或者风控审核失败的订单</span>	
     	<div class="jqGrid_wrapper">
         <table id="table_list_1"></table>
         <div id="pager_list_1"></div>
    	</div>
   </div>
   
   <div style="display: none;" id="zxfk">
   	   <div class="business-padding">
		  <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table" id="zxQueryCreditApplySubs">
		</table>	
       </div>
       <div class="padding-nono">
        <table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8"  width="100%">
			<tr>
				<td width="100%" align="center">
					 <div class="ibox-content">
			              <button type="button" class="btn dpbtn_red " onclick="baocun();">确定</button>
			              <button id="" class="btn dpbtn_grey" type="button" onclick="canCel();">取消</button>
			          </div>
				</td>
			</tr>
		</table>
   	 </div>
   </div>
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>	
    
    <!-- layerDate plugin javascript -->
    <script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    
    
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
	    
	    jQuery(function($) { 
	    	var start = {
	    			  elem: '#startDateStart', 
	  		          event: 'focus' ,
	    			  format: 'YYYY-MM-DD',
	    			  min: '1970-01-01', //设定最小日期为当前日期
	    			  max: laydate.now(), //最大日期
	    			  istime: false,
	    			  istoday: false,
	    			  choose: function(datas){
	    				 $('#buttonall .btn').removeClass('butactive');
	    			     end.min = datas; //开始日选好后，重置结束日的最小日期
	    			     end.start = datas; //将结束日的初始值设定为开始日
	    			  },
	    			  clear:function(){
	    				  $('#buttonall .btn').removeClass('butactive');
	    				  end.min = '1970-01-01';
	    				  end.start = '1970-01-01';
	    			  }
	    			};
	    	
	    	var end = {
	    			  elem: '#startDateEnd', 
	  		          event: 'focus' ,
	    			  format: 'YYYY-MM-DD',
	    			  min: '1970-01-01',
	    			  max: laydate.now(),
	    			  istime: false,
	    			  istoday: true,
	    			  choose: function(datas){
	    				 $('#buttonall .btn').removeClass('butactive');
	    			    start.max = datas; //结束日选好后，重置开始日的最大日期
	    			  },
	    			  clear:function(){
	    				  $('#buttonall .btn').removeClass('butactive');
	    				  start.max = '2099-12-31';
	    			  }
	    			}; 
	    	laydate(start);
	    	laydate(end);
	    	
	    	$('#startDateStart').val(laydate.now(-6));
	    	end.min = laydate.now(-6);
			end.start = laydate.now(-6);
			$('#startDateEnd').val(laydate.now(0));
			start.max = laydate.now(0);
			
	    	getData();
	    });
	    
	    var baocun = function(){
	    	var cusName = $('#peiou_cusname').val();
	    	var cusNo = $('#peiou_cusno').val();
	    	var applyId = $('#peiou_applyid').val();
	    	var busiId = $('#peiou_busiid').val();
	    	var subApplyId = $('#peiou_subapplyid').val();
	    	layer.confirm('即将由['+cusName + '('+cusNo + ')]创建新订单。注：更换后请详细检查“资料登记”页，附件资料需重新上传', {
	    		  btn: ['确定','取消'],//按钮
	    		  title:"变更主借人" 
	    		}, function(){
	    			layer.closeAll();
	    			$.dpAjax({
	          	    	url:'${basePath}/ZxZhuJieRenGengHuanController/change',
	           			data:{applyId:applyId,busiId:busiId,subApplyId:subApplyId},
	           			success: function(datas){
	           				  layer.closeAll();
	           				  if(datas.flag == "100100") {
	           					layer.msg("变更主借人成功!", {icon: 6, time: 1000});
	           					refresh();
	                            return;
	          				  }
	          				  if(datas.flag == "100200") {
	          					  $.fn.showDatas({"datas":datas});
	                          	  return;
	                          }
	          				  layer.msg(datas.message, {icon: 2});
	                       }
	          	     });
	    		});
	    }
	    
	    var canCel = function(){
	    	layer.close(openIndex);	
	    }
		var winWidth = $('div.ibox-content').width();
		var winHeight = document.body.offsetHeight - 330;
	    var openIndex;
	    var getData = function(){
	     var win = winWidth / 13;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
		  jQuery("#table_list_1").jqGrid({
			url:'${basePath}/ZxZhuJieRenGengHuanController/changeList',
	//		postData:{startDateStart:laydate.now(-6),startDateEnd:laydate.now(0),datasources:1},
			postData:{startDateStart:laydate.now(-6),startDateEnd:laydate.now(0)},
	        datatype : "json",
	        colNames : [ '主键', '征信查询申请ID','业务ID','配偶征信子查询ID','征信起始日期', '征信截止日期', '最近业务状态', '当前主借人', '配偶', '身份证号码', '贷款额','订单类型', /* '经销商', '经销商等级', */'部门','业务员', '银行'],
	        colModel : [ 
	                     {name: 'replaceId', index: 'ZCQ.id', hidden:true},
	                  	 {name: 'queryCreditApplyId',index: 'ZCQ.queryCreditApplyId', hidden:true},
	                  	 {name: 'busiId',index: 'YW.id', hidden:true},
	                  	 {name: 'queryCreditApplySubId',index: 'ZCQ.queryCreditApplySubId', hidden:true},
	                     {name: 'startDate',index: 'ZCQ.startDate',width: 180,align: "center",formatter:function(a,b,c){
	                       	 return formateToDate(a);
	                     }},
	                     {name: 'endDate',index: 'ZCQ.endDate',width: 180,align: "center",formatter:function(a,b,c){
	                       	 return formateToDate(a);
	                     }},
	                  	 {name: 'busiStatusDisplay',index: 'YW.busiStatus',width: 150,align: "center"},
	               		 {name: 'currentCusName',index: 'ZZQCAS.cusName',width: 130,align: "center"},
	               		 {name: 'cusName',index: 'ZQCAS.cusName',width: 130,align: "center"},
	            		 {name: 'cusNo',index: 'ZQCAS.cusNo',width: 180,align: "center"},
	            		 {name: 'realLoanAmount',index: 'YW.realLoanAmount',width: 180,align: "center",formatter:function(a,b,c){
	                       	 return a?showNumber(a):'-';
	                     }},
	            		 {name: 'channelTypeDisplay',index: 'YW.channelType',width: 130,align: "center"},
	            		/*  {name: 'dealerName',index: 'BDI.dealerName',width: 300,align: "center"},
	            		 {name: 'dealerLevelDisplay',index: 'BDI.dealerLevel',width: 130,align: "center"}, */
	            		 {name: 'orgName',index: 'BBU.orgName',width: 130,align: "center"},
	            		 {name: 'salersmanName',index: 'SIT.name',width: 130,align: "center"},
	            		 {name: 'bankCodeDisplay',index: 'ZCQ.bankCode',width: 300,align: "center"}
	                   ],
              mtype : "post",
              height: winHeight,
              width:winWidth,  
              shrinkToFit:false,
              autoScroll: false,
              rowNum: 15,
              rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              hidegrid: false,
              multiselect : false,
              sortable:true,
              sortname:'ZCQ.startDate',
              sortorder:'desc',
              altRows:true,
              altclass:'someClass',
              ondblClickRow:function(rowId,v,e)  {
            	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
            	  var applyId = rowData.queryCreditApplyId;
            	  var cusName = rowData.cusName;
            	  var cusNo = rowData.cusNo;
            	  var busiId = rowData.busiId;
            	  var subApplyId = rowData.queryCreditApplySubId;
            	  if(!applyId || applyId == '') {
            		  layer.msg('缺失该客户征信查询申请标识,请联系管理员处理', {icon: 5});
            		  return;
            	  }
           // 	  var datasources = document.getElementById('datasources').value;
            	  $.dpAjax({
          	    	url:'${basePath}/ZxZhuJieRenGengHuanController/queryCreditPeoples',
           			data:{applyId:applyId},
           			success: function(datas){
           				  if(datas.flag == "100100") {
           					 var html = "";
           					 var records = datas.result;
           					 if(records && records.length > 0){
          	 					 html += '<input id="peiou_cusname" name="peiou_cusname" value="' + cusName +'" type="hidden"/>';
          	 					 html += '<input id="peiou_cusno" name="peiou_cusno" value="' + cusNo +'" type="hidden"/>';
          	 					 html += '<input id="peiou_applyid" name="peiou_applyid" value="' + applyId +'" type="hidden"/>';
          	 					 html += '<input id="peiou_busiid" name="peiou_busiid" value="' + busiId +'" type="hidden"/>';
          	 					 html += '<input id="peiou_subapplyid" name="peiou_subapplyid" value="' + subApplyId +'" type="hidden"/>';
           						 for(var i = 0; i < records.length; i++){
          	 						 var record = records[i];
          	 						 html += '<tr><td align="right"><label class="control-label">' + (i > 2 ? '' : record.creditPeopleTypeDisplay + '：') + '</label></td>';
          	 						 html += '<td><input class="form-control" style="width:300px;" readonly="readonly" value="' + record.cusName + '(' + record.cusNo + ')"/></td></tr>';
           						 }
           					 }
           					 $('#zxQueryCreditApplySubs').html(html);
           					 openIndex = layer.open({
                     		    title:"变更主借人",
         	  	        	    type: 1,
         	  	        	    area: ['450px', '40%'], //宽高
         	  	        	    content: $('#zxfk')
         	          	     });
          					 return;
          				  }
          				  if(datas.flag == "100200") {
          					  $.fn.showDatas({"datas":datas});
                          	  return;
                          }
          				  layer.msg(datas.message, {icon: 2});
                       }
          	     });
              },
              jsonReader : {
            	  root:"result.rows",
            	  page: "result.page",
            	  total: "result.total",
            	  records: "result.records",
            	  repeatitems: false,
            	  id: "replaceId"
              },
              loadComplete:function(datas){
            	  if (datas.flag == "100100") {
                      layer.msg("查询成功!", {icon: 6, time: 1000});
                      return;
                  }
            	  if (datas.flag == "100200") {
                      $.fn.showDatas({"datas": datas});
                      return;
                  }
                  layer.msg(datas.message, {icon: 2});
              },
              loadComplete:function(datas){
	         	  if (datas.flag == "100100") {
	                   layer.msg("查询成功!", {icon: 6, time: 1000});
	                   return;
	               }
	         	  if(datas.flag == '100802') {
	 				  top.location.href = thisLoginUrl;
	 				  return;
	 			  }

	         	  layer.msg(datas.message, {icon: 2});
	           }
	      });
	    }	    
	    
	    window.onresize = function()
	    {
	    	$("#table_list_1").setGridWidth($(window).width()-80);
	    }
	    
	    var query = function(start, end){
	    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
	    	var data = {};
	    	//data.datasources = document.getElementById('datasources').value || '1';
	    	data.peiouName = document.getElementById('peiouName').value || '';
	    	data.peiouNo = document.getElementById('peiouNo').value || '';
	    	data.zhujierenName = document.getElementById('zhujierenName').value || '';
	    	/* data.zhujierenNo = document.getElementById('zhujierenNo').value || ''; */
	    	if(start != null && typeof start != 'undefined') {
	    		document.getElementById('startDateStart').value = laydate.now(start);
	    		document.getElementById('startDateEnd').value = laydate.now(end);
	    	}
	    	data.startDateStart = document.getElementById('startDateStart').value.trim();
	    	data.startDateEnd = document.getElementById('startDateEnd').value.trim();
	    	
	    	$.extend(postData, data);
	    	refresh();
	    }
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
	    }
    </script>
</body>
</html>
